package net.sxnic.item.zzdw.action;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import net.sxinfo.core.dao.Page;
import net.sxinfo.core.util.WebUtils;
import net.sxnic.item.ItemConstants;
import net.sxnic.ugr.user.User;
import net.sxnic.ugr.user.UserManager;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;

@SuppressWarnings("serial")
public class Browse extends ZzdwAction {
	
	private String deptCode;
	
	private String deptName;
	
	@Autowired
	private UserManager userManager;
	
	private Page datas;

	public String execute() throws Exception {

		int page = WebUtils.getPageNumber(request);
		int pageSize = WebUtils.getPageSize(request);

		Set<String> depts = new HashSet<String>();
		Map<String,String> zzdwMap = ItemConstants.ZZDW_MAP.get(ItemConstants.SYSTEM_CALALOG_ALIAS);
		for(String key : zzdwMap.keySet())
		{
			depts.add(key);
		}
		DetachedCriteria dc = DetachedCriteria.forClass(User.class);
		dc.createAlias("dept", "d").add(Restrictions.in("d.code", depts));
		
		dc.addOrder(Order.asc("userOrder"));

		datas = userManager.getPageByDetachedCriteria(page, pageSize, dc);

		return SUCCESS;
	}

	public Page getDatas() {
		return datas;
	}

	public void setDatas(Page datas) {
		this.datas = datas;
	}

	public String getDeptCode() {
		return deptCode;
	}

	public void setDeptCode(String deptCode) {
		this.deptCode = deptCode;
	}

	public String getDeptName() {
		return deptName;
	}

	public void setDeptName(String deptName) {
		this.deptName = deptName;
	}
	
}
